<?php

use yii\db\Migration;
use yii\db\Schema;

/**
 * Class m201110_020658_CREATE_TABLE_INIT
 */
class m201110_020658_CREATE_TABLE_INIT extends Migration
{
    /**
     * {@inheritdoc}
     */
    public function safeUp()
    {
         $tableOptions = 'CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE=InnoDB';

         // 客户信息
        $this->createTable('ai_customer', [

            "id" =>             Schema::TYPE_PK,
            "name" =>           Schema::TYPE_STRING. "(255) NOT NULL COMMENT '客户名称'",
            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1 正常 2禁止 '",
            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间' ",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",

        ], $tableOptions);

        // 团队信息
        $this->createTable('ai_contract', [

            "id" =>             Schema::TYPE_PK,
            "code" =>           Schema::TYPE_STRING. "(255) NOT NULL COMMENT '合同编号'",
            "type" =>           Schema::TYPE_INTEGER. "(1) DEFAULT  '1' COMMENT '1 内贸 2外贸 '",
            "customer_id" =>    Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '客户ID'",
            "sale_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '销售人员ID'",
            "sale_currency" =>   Schema::TYPE_STRING. "(10) NULL COMMENT '合同币种'",
            "sale_price" =>      Schema::TYPE_DECIMAL."(10,2) DEFAULT '0.00' COMMENT '合同金额' ",

            "payment_type" =>        Schema::TYPE_STRING. "(128)  NULL COMMENT '收款方式'",
            "pay_currency" =>   Schema::TYPE_STRING. "(10) NULL COMMENT '收款币种'",
            "pay_price" =>      Schema::TYPE_DECIMAL."(10,2) DEFAULT '0.00' COMMENT '收款金额' ",
            "exchange_currency" =>   Schema::TYPE_STRING. "(10) NULL COMMENT '差额币种'",
            "exchange_price" =>      Schema::TYPE_DECIMAL."(10,2) DEFAULT '0.00' COMMENT '汇兑差额' ",

            "oper_id" =>       Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '商务操作ID'",
            "express_num" =>   Schema::TYPE_STRING. "(128)  NULL COMMENT '快递号'",
            
            "finance_id" =>       Schema::TYPE_INTEGER."(11) DEFAULT '0' COMMENT '财务ID'",

            "is_invoice" =>    Schema::TYPE_INTEGER. "(1) DEFAULT  '1' COMMENT '是否开票'",
            "invoice_date" =>      Schema::TYPE_DATE. " NULL COMMENT '开票日期' ",
            "invoice_no" =>   Schema::TYPE_STRING. "(128)  NULL COMMENT '开票号'",
            "invoice_company" =>   Schema::TYPE_STRING. "(128)  NULL COMMENT '开票公司'",
            "invoice_currency" =>   Schema::TYPE_STRING. "(10) NULL COMMENT '开票币种'",
            "invoice_price" =>   Schema::TYPE_DECIMAL."(10,2) DEFAULT '0.00' COMMENT '开票金额' ",

            "is_back" =>    Schema::TYPE_INTEGER. "(1) DEFAULT  '1' COMMENT '是否回款'",
            "back_date" =>      Schema::TYPE_DATE. " NULL COMMENT '回款日期' ",
            "back_company" =>   Schema::TYPE_STRING. "(128)  NULL COMMENT '回款公司'",
            "back_currency" =>   Schema::TYPE_STRING. "(10) NULL COMMENT '回款币种'",
            "back_price" =>   Schema::TYPE_DECIMAL."(10,2) DEFAULT '0.00' COMMENT '回款金额' ",

            "user_id" =>        Schema::TYPE_INTEGER.   "(10) DEFAULT '0' COMMENT '创建人ID'",
            "status" =>         Schema::TYPE_INTEGER.   "(1) DEFAULT  '1' COMMENT '1提交 2已订货 3开票 4已发货 5回款 10删除'",
            "created_at" =>     Schema::TYPE_DATETIME. " NULL COMMENT '创建时间' ",
            "updated_at" =>     Schema::TYPE_TIMESTAMP. " NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP",

        ], $tableOptions);

    }

    /**
     * {@inheritdoc}
     */
    public function safeDown()
    {
        echo "m201110_020658_CREATE_TABLE_INIT cannot be reverted.\n";

        return false;
    }

    /*
    // Use up()/down() to run migration code without a transaction.
    public function up()
    {

    }

    public function down()
    {
        echo "m201110_020658_CREATE_TABLE_INIT cannot be reverted.\n";

        return false;
    }
    */
}
